<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('供应商资料转移')" />
</head>
<body>
	<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "crm/provider";
	/*]]>*/
</script>
<script type="text/javascript">
var $,layer,form,table,datas,customerInfoList,gprovides;
layui.use(['table','form','layer','jquery'], function () {
     $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
    if(window.location.href.split("=")[1] ){
    	gprovides=[{'gprovide':window.location.href.split("=")[1]}];
	}else{
    	gprovides=parent.layui.table.checkStatus('dhtable').data;	
	}
    $.ajax({
        url: prefix +"/map",
        type: 'post',
        dataType: 'json',
        data: {'providerInfoItems':JSON.stringify(gprovides)},
        success: function(result) {
        	customerInfoList=result.data;
            $.tablelist.init({
                elem: '#dhtable'
                ,data:customerInfoList
                ,page:false
                ,limit:10000
                ,cols: [[
               	 {type:'numbers',rowspan: 2},
         	     	{field: 'gprovide',title: '供应商编号',rowspan: 2},
        	        {field: 'gpName',title: '供应商名称',rowspan: 2},
        	        {field: 'bUser',title: '所属采购员',rowspan: 2},
        	        {field: 'bUserName',title: '所属采购员',rowspan: 2},
        	       	{align: 'center',title: '转入员工',colspan:6}
        	       ], [
        	        {field: 'newbUser',title: '采购员编号',event:'selectU',templet:function(d){
        	        	var str=`<i class="layui-icon layui-icon-more" style="position: absolute;right: 10px;top: 9px;"></i>`;
       	            	return  d.newbUser?d.newbUser+str:str;
       	        	}},
        	       	{field: 'userName',title: '采购员名称'},
        	        {field: 'newbDept',title: '采购编号',hide:true},
        	      	{field: 'orgName',title: '采购部门'},
        	      	{field: 'newcID',title: '公司编号',hide:true},
        	      	{field: 'cidName',title: '公司名称'}
        	    ]
            	]
               ,height:'full-36'
            });
        }
    });
	table.on('tool(ftable)', function(obj){
        var data = obj.data,tr = obj.tr,vIndex;//此处的data就是表格里面的值
        vIndex=$("tr").index(obj.tr)-2;
        if(obj.event === 'selectU'){
            $.modal.open('选择转入员工','/system/user/userselect?pagetype=radio','560','465',function(index){
		        var res = window["layui-layer-iframe" + index].callbackdata();
		        if(!!res){
		        	$.each(table.cache.dhtable,function(i,v){
						if(v['newbUser'] && v.LAY_TABLE_INDEX==vIndex){//缓存表内的下标和当前事件行下标的判断
							v['newbUser']=res.userId;
							v['userName']=res.userName;
							v['newbDept']=res.deptPath;
							v['orgName']=res.deptName;
							v['newcID']=res.cid;
							v['cidName']=res.cidName;
						}
						if(!v['newbUser']){
							v['newbUser']=res.userId;
							v['userName']=res.userName;
							v['newbDept']=res.deptPath;
							v['orgName']=res.deptName;
							v['newcID']=res.cid;
							v['cidName']=res.cidName;
						}
		        	});
		        	table.reload('dhtable',{
		    			data : table.cache.dhtable
		    		});
		       	 	layer.closeAll();
		        }else{
		        	layer.msg("请选择人员！", {icon:7});
		        }
		    });
        };
        
	});
 });
//提交调用的方法
function submitHandler() {
	var transferList=[];
	$.each(table.cache.dhtable,function(i,v){
		transferList[i]={};
		transferList[i]['oldPUser']=v['bUser'];
		transferList[i]['newPUser']=v['newbUser'];
		transferList[i]['gprovide']=v['gprovide'];
		v['bUser']=v['newbUser'];
		v['bDept']=v['newbDept'];
		v['cID']=v['newcID'];
	});
    $.operate.save(prefix + "/editbuserpost", {'providerInfoItems':JSON.stringify(table.cache.dhtable, null, 2),'providerTransferItems':JSON.stringify(transferList,null, 2)});
}
</script>
</body>
</html>